#! /bin/bash

create_dir(){
    for i in $(seq 1 3); do mkdir -p ./redis/r$i; sudo chmod -R 777 ./redis/r$i; done
}

main(){
    docker-compose  ps | grep redis > /dev/null
    if [ $? != 0 ]
    then
        create_dir
        # 镜像默认是2个哨兵同意才进行主从切换，所有这里启动三个sentinel
        docker-compose up --scale redis-sentinel=3 -d
        clear
        docker-compose ps
    else
        echo "Confirm to stop the current service!  yes | no"
        read -p "> "  selet
        case $selet in
        y | yes)
            docker-compose down
            ;;
        n | no)
            exit 0
            ;;
        *)
            echo "请输入 yes | no "
            ;;
        esac
    fi
}

main